﻿/*
   Copyright 2012 Dmitry Bratus

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Flower.Services.Data;
using NUnit.Framework;
using Flower.Directory.Util;

namespace Flower.Directory.Util.Tests
{
    [TestFixture]
    public class SerializationDeserializationTests
    {
        [Test]
        public void Assembly()
        {
            var entry = new Assembly
            {
                Id = "#123",
                Name = "Assembly",
                CreatedOn = new DateTime(1000),
                UpdatedOn = new DateTime(2000),
                Image = new byte[] { 1, 2, 3 }
            };

            var deserializedEntry = 
                entry
                    .ToBlob(BlobFormat.BinXml)
                    .To<Assembly>();
        }

        [Test]
        public void Folder()
        {
            var entry = new Folder
            {
                Id = "#123",
                Name = "Folder",
                CreatedOn = new DateTime(1000),
                UpdatedOn = new DateTime(2000)
            };

            var deserializedEntry =
                entry
                    .ToBlob(BlobFormat.BinXml)
                    .To<Folder>();
        }

        [Test]
        public void Link()
        {
            var entry = new Link
            {
                Id = "#123",
                Name = "Link",
                CreatedOn = new DateTime(1000),
                UpdatedOn = new DateTime(2000),
                Target = "#target"
            };

            var deserializedEntry =
                entry
                    .ToBlob(BlobFormat.BinXml)
                    .To<Link>();
        }

        [Test]
        public void Message()
        {
            var entry = new Message
            {
                Id = "#123",
                Name = "Message",
                CreatedOn = new DateTime(1000),
                UpdatedOn = new DateTime(2000),
                Data = new Blob { Format = BlobFormat.BinXml, Data = new byte[] { 1, 2, 3 } }
            };

            var deserializedEntry =
                entry
                    .ToBlob(BlobFormat.BinXml)
                    .To<Message>();
        }

        [Test]
        public void Process()
        {
            var entry = new Process
            {
                Id = "#123",
                Name = "Process",
                CreatedOn = new DateTime(1000),
                UpdatedOn = new DateTime(2000),
                Workflow = "Workflow"
            };

            var deserializedEntry =
                entry
                    .ToBlob(BlobFormat.BinXml)
                    .To<Process>();
        }

        [Test]
        public void Processor()
        {
            var entry = new Processor
            {
                Id = "#123",
                Name = "Processor",
                CreatedOn = new DateTime(1000),
                UpdatedOn = new DateTime(2000),
                Configuration = new Blob { Format = BlobFormat.BinXml, Data = new byte[] { 1, 2, 3 } }
            };

            var deserializedEntry =
                entry
                    .ToBlob(BlobFormat.BinXml)
                    .To<Processor>();
        }

        [Test]
        public void Role()
        {
            var entry = new Role
            {
                Id = "#123",
                Name = "Role",
                CreatedOn = new DateTime(1000),
                UpdatedOn = new DateTime(2000)
            };

            var deserializedEntry =
                entry
                    .ToBlob(BlobFormat.BinXml)
                    .To<Role>();
        }

        [Test]
        public void ServiceContainer()
        {
            var entry = new ServiceContainer
            {
                Id = "#123",
                Name = "ServiceContainer",
                CreatedOn = new DateTime(1000),
                UpdatedOn = new DateTime(2000),
                Configuration = new Blob { Format = BlobFormat.BinXml, Data = new byte[] { 1, 2, 3 } }
            };

            var deserializedEntry =
                entry
                    .ToBlob(BlobFormat.BinXml)
                    .To<ServiceContainer>();
        }

        [Test]
        public void Set()
        {
            var entry = new Set
            {
                Id = "#123",
                Name = "Set",
                CreatedOn = new DateTime(1000),
                UpdatedOn = new DateTime(2000),
                MessageType = "MessageType",
                Capacity = 1
            };

            var deserializedEntry =
                entry
                    .ToBlob(BlobFormat.BinXml)
                    .To<Set>();
        }

        [Test]
        public void State()
        {
            var entry = new State
            {
                Id = "#123",
                Name = "State",
                CreatedOn = new DateTime(1000),
                UpdatedOn = new DateTime(2000),
                Data = new Blob { Format = BlobFormat.BinXml, Data = new byte[] { 1, 2, 3 } }
            };

            var deserializedEntry =
                entry
                    .ToBlob(BlobFormat.BinXml)
                    .To<State>();
        }

        [Test]
        public void Workflow()
        {
            var entry = new Workflow
            {
                Id = "#123",
                Name = "Workflow",
                CreatedOn = new DateTime(1000),
                UpdatedOn = new DateTime(2000),
                DefinitionType = "DefinitionType"
            };

            var deserializedEntry =
                entry
                    .ToBlob(BlobFormat.BinXml)
                    .To<Workflow>();
        }
    }
}
